<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>interface demo</title>
    <!-- <script src="https://cdn.bootcdn.net/ajax/libs/lodash.js/4.17.21/lodash.min.js"></script> -->
    <script src="../lodash/lodash.min.js"></script>
    <script src="../helpers/bing.js"></script>
  </head>
  <body>
    <script>
      //   fetch("https://history.macaumarksix.com/history/macaujc2/y/2020")
      //     .then((response) => response.json()) // 解析响应为 JSON
      //     .then((data) => {
      //       console.log("Success:", data); // 处理响应数据
      //     })
      //     .catch((error) => {
      //       console.error("Error:", error); // 处理错误
      //     });

      function getHistory(year) {
        return new Promise((resolve, reject) => {
          fetch(`https://history.macaumarksix.com/history/macaujc2/y/${year}`)
            .then((response) => response.json()) // 解析响应为 JSON
            .then((res) => {
              const list = res.data.reverse().map((item) => {
                return {
                  number: item.openCode.match(/(\d+)$/)[0],
                  time: item.openTime.match(/^\d{4}-\d{2}-\d{2}/)[0],
                };
              });
              resolve(list);
            });
        });
      }
      // 2020年 226
      // 2021年 365
      // 2022年 365
      // 2023年 365
      // 2024年 365

      const historyYears = [2020, 2021, 2022, 2023];

	  Promise.all(historyYears.map(getHistory))
	  	.then((res) => {
			console.log(res);
		})
		.catch((err) => {
			console.log(err);
		})

    </script>
  </body>
</html>
